<?php

namespace App\Admin\Controllers;

use App\Models\Setting;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class SettingController extends AdminController
{
    protected $title = '设置';
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Setting(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('gaunyuwomen');
            $grid->column('lianxidianhua');
            $grid->column('yinsi');
            $grid->column('yonghuxieyi');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Setting(), function (Show $show) {
            $show->field('id');
            $show->field('gaunyuwomen');
            $show->field('lianxidianhua');
            $show->field('yinsi');
            $show->field('yonghuxieyi');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Setting(), function (Form $form) {
            $form->tab('关于我们',function ($form){
                $form->textarea('guanyu','内容');
            })->tab('隐私政策',function ($form){
                $form->textarea('yinsi','内容');
            })->tab('用户协议',function ($form){
                    $form->textarea('yonghuxieyi','内容');
            })->tab('客服设置',function ($form){
                $form->text('lianxidianhua','联系电话');
            })->tab('热门搜索',function ($form){
                $form->text('hot_key','热门搜索关键词')->help('多个关键词用英文逗号隔开');
            })->tab('首页轮播',function ($form){
                $form->multipleImage('lunbo', '轮播图')->removable()->uniqueName()->chunkSize(1024)->autoUpload()->sortable()->help('建议尺寸：1000*300');
            });
            $form->saved(function (Form $form, $result) {

                return $form->response()->success('保存成功')->redirect('/setting/1/edit');
            });
        });
    }
}
